
$(function(){
	$.fn.extend({
		loadCombox:function(on_type){
			this.find("input[on_type='"+on_type+"']").each(function(e,_this){
				var selectId="select";
				var select_id=$(_this).attr("id");
				var select_value=$(_this).attr("value");
				var select_loadUrl=$(_this).attr("loadUrl");
				var select_no_name=$(_this).attr("no_name");
				var select_parMs=$(_this).attr("parMs");
				var selectStr="<select class='col-xs-10 col-sm-5' id='"+select_id+selectId+"'></select>";
				$(_this).after(selectStr);
				$.post(select_loadUrl,select_parMs,function(data){
					var json=$.parseJSON(data);
					var comboxJson=json.obj.results;
					var optionStr="<option value='-1'>请选择</option>";
					for(var i=0;i<comboxJson.length;i++){
						if(select_value=="" || select_value==null){
							optionStr+="<option value='"+comboxJson[i][''+select_id+''] +"'>"+comboxJson[i][''+select_no_name+'']+"</option>";
						}else{
							var selected="";
							if(select_value==comboxJson[i][''+select_id+'']){
								selected ="selected='selected'";
							}
							optionStr+="<option value='"+comboxJson[i][''+select_id+'']+"'  "+selected+">"+comboxJson[i][''+select_no_name+'']+"</option>";
						}
					}
					$("#"+select_id+selectId).append(optionStr);
				});
				$("#"+select_id+selectId).change(function(){
					var onVal=$(this).val();
					$(_this).attr("value",onVal);
					
				});
			});
		},loadFy:function(json,cl,params,url,isFy){
			$("#fy").remove();
				var _tab_this=this;
				_tab_this.after("<div class='modal-footer no-margin-top' style='display: none;' id='fy'></div>");
				$("#fy").append("<ul class='pagination pull-right no-margin'></ul>");
				var sum=json.obj.totalRecord;
				if(sum>0){
					$("#fy").show();
					var prevDis="";
					if(json.obj.pageNum==1){
						prevDis="disabled";
					}
					var yfList="<li class='prev "+prevDis+"' id='diyiye'><a href='javascript:' onclick=''>";
					yfList+="第一页</a></li>";
					yfList+="<li class='prev "+prevDis+"' id='shangyiye'><a href='javascript:' onclick=''>";
					yfList+="<i class='icon-double-angle-left'></i></a></li>";
					for(var i=1;i<=json.obj.totalPage;i++){
						
						var acStr="";
						if(json.obj.pageNum==i){
							acStr="active";
						}

						yfList+="<li class='dangqian "+acStr+"' name='"+i+"'>";
						yfList+="<a href='javascript:' onclick=''>"+i+"</a></li>";
//						if(json.obj.totalPage<=6){
//						}else{
//							var numPage=json.obj.pageNum-i;
//							if(numPage==2){
//								yfList+="<li "+acStr+">";
//								yfList+="<a href='javascript:' >...</a></li>";
//							}else if(numPage<=2){
//								if(i<=3 || (json.obj.totalPage-i)<=2){
//									yfList+="<li "+acStr+">";
//									yfList+="<a href='javascript:' onclick=''>"+i+"</a></li>";
//								}else if(i==4){
//									yfList+="<li "+acStr+">";
//									yfList+="<a href='javascript:' >...</a></li>";
//								}
//							}
//						}
						
					}
					var nextDis="";
					if(json.obj.pageNum==json.obj.totalPage){
						nextDis="disabled";
					}
					yfList+="<li class='next "+nextDis+"' id='xiayiye'><a href='javascript:' onclick=''>";
					yfList+="<i class='icon-double-angle-right'></i></a></li>";
					
					yfList+="<li class='next "+nextDis+"' id='zuihou'><a href='javascript:' onclick=''>";
					yfList+="最后页</a></li>";
					$("#fy>ul").find("li").remove();
					$("#fy>ul").append(yfList);
					
					$("#diyiye").click(function(){
						params.pageNum=1;
						_tab_this.loadTbl(cl,params,url,true);
					});
					$("#shangyiye").click(function(){
						if(params.pageNum>1){
							params.pageNum=params.pageNum-1;
							_tab_this.loadTbl(cl,params,url,true);
						}
					});
					$(".dangqian").click(function(){
						var i=$(this).attr("name");
						params.pageNum=i;
						_tab_this.loadTbl(cl,params,url,true);
					});
					$("#xiayiye").click(function(){
						if(json.obj.totalPage>params.pageNum){
							params.pageNum=params.pageNum+1;
							_tab_this.loadTbl(cl,params,url,true);
						}
					});

					$("#zuihou").click(function(){
						params.pageNum=json.obj.totalPage;
						_tab_this.loadTbl(cl,params,url,true);
					});
				}
			
		},loadTbl:function(cl,params,url,isFy){
			var _tab_this=this;
			if(isFy==false){
				$("#fy").remove();
			}
			$.post(url,params,function(data){
				var json=$.parseJSON(data);
				if(json.res=="1"){
					var result=json.obj.results;
					var tdStr="<tr>";
					for(var i=0;i<result.length;i++){
						for(var j=0;j<cl.length;j++){
							var clFun=cl[j].cl;
							var tbl_html="";
							if(typeof clFun=="function" && clFun!=null){
								tbl_html=clFun(j,result[i][''+cl[j].name+'']);
							}
							if(tbl_html!=""){
								tdStr+="<td>"+tbl_html+"</td>";
							}else{
								tdStr+="<td>"+result[i][''+cl[j].name+'']+"</td>";
							};
						}
						tdStr+="</tr>";
					}
					_tab_this.children("tbody").eq(0).find("tr").remove();
					_tab_this.children("tbody").eq(0).append(tdStr);
					
					if(isFy){
						_tab_this.loadFy(json,cl,params,url,isFy);
					}
				}else{
					_tab_this.children("tbody").eq(0).find("tr").remove();
				}
			});
		},loadInfo:function(cl,params,url,jpath,time){
			var _this=this;
			$.post(url,params,function(data){
				var json=$.parseJSON(data);
				console.log(json);
				if(json.res=="1"){
					var tdStr="";
					var result;
					if(json.obj!=null){
						try{
							result=json.obj.results;
							for(var i=0;i<result.length;i++){
								tdStr+="<div class='row news'>";
								tdStr+="<div class='col-12'>";
								tdStr+="<div class='row news_con' id="+result[i][''+cl[0].name+'']+">";
								tdStr+="<div class='col-4 con_img'>";
								tdStr+="<img src="+jpath+result[i][''+cl[1].name+'']+" />";
								tdStr+="</div>";
								tdStr+="<div class='col-8 text'>";
								tdStr+="<div class='row'>";
								tdStr+="<div class='col-12 font'>";
								tdStr+="<h6>"+result[i][''+cl[2].name+'']+"</h6>";
								tdStr+="</div>";
								tdStr+="</div>";
								tdStr+="<div class='row'>";
								if(result[i][''+cl[3].name+''].length > 60){
									tdStr+="<div class='col-12 font_ell'>"+result[i][''+cl[3].name+''].substring(0,80)+".....</div>";
								}else{
									tdStr+="<div class='col-12 font_ell'>"+result[i][''+cl[3].name+'']+"</div>";
								}
								tdStr+="</div>";
								tdStr+="<div class='row font'>";
								if(time==true){
									tdStr+="<div class='col-6'>"+result[i][''+cl[4].name+'']+"</div>";
									tdStr+="<div class='col-6' align='right'>来源:"+result[i][''+cl[5].name+'']+"</div>";
								}else{
									tdStr+="<div class='col-6'></div>";
									tdStr+="<div class='col-6' align='right'>"+result[i][''+cl[4].name+'']+"</div>";
								}
								tdStr+="</div></div></div></div></div>";
							}
						}catch(err){
							result=json.obj;
							tdStr="";
							tdStr+="<div class='row news' style='padding: 1rem 2rem;font-size: 0.8rem;'>";
							result=json.obj;
							tdStr+="<div class='col-12 news_con'>用户姓名:"+result.UsersName+"</div>";
							tdStr+="<div class='col-12 news_con'>企业名称:"+result.EnterpriseName+"</div>";
							tdStr+="<div class='col-12 news_con'>手机号码:"+result.Phone+"</div>";
							tdStr+="<div class='col-12 news_con'>用户积分:"+result.UserIntegral+"</div>";
							tdStr+="<div class='col-12 news_con'>企业简介:"+result.CompanyProfile+"</div>";
							tdStr+="<div class='col-12 news_con'>用户行业:"+result.IndustryName+"</div>";
							tdStr+="<div class='col-12 news_con'>用户分类:"+result.ClassificationName+"</div>";
							tdStr+="<div class='col-12 news_con'>登陆账号:"+result.LoginAccount+"</div>";
							tdStr+="</div>";
						}
					}else{
						tdStr+="<div class='row news' style='padding: 1rem 2rem;font-size: 0.8rem;'>";
						tdStr+="<div class='col-12 news_con' style='text-align: center;'><a href='"+jpath+"/front/register'>请登录</a></div>";
						tdStr+="</div>";
					}
					_this.children().remove();
					_this.append(tdStr);
				}else{
					_this.children().remove();
				}
			});
		},loadProductInfo:function(params,url,jpath,isImg){
			var _this=this;
			$.post(url,params,function(data){
				var json=$.parseJSON(data);
				if(json.res=="1"){
					var result=json.obj.results;
					var tdStr="";
					if(result!=null){
						for(var i=0;i<result.length;i++){
							if(isImg){
								tdStr+='<div class="row con_n" >';
								tdStr+='<div class="col-1"></div>';
								if(result[i].AuditStatus==0){
									tdStr+='<div class="col-10 shadows bg_color" id="'+result[i].ProductId+'">';
								}else if(result[i].AuditStatus==1){
									tdStr+='<div class="col-10 shadows" id="'+result[i].ProductId+'">';
								}
								tdStr+='<div class="row">';
								tdStr+='<div class="col-9">';
								tdStr+='<div class="row">';
								tdStr+='<div class="col-12">';
								tdStr+=' <div class="row">';
								tdStr+=' <div class="col-8 special">';
								tdStr+=' <h3>'+result[i].Money+'万元</h3>';
								tdStr+='<h5>'+result[i].Title+'</h5>';
								tdStr+='</div>';
								tdStr+='<div class="col-4 text">';
								tdStr+='<p>公司规模: '+result[i].Scale+'</p>';
								tdStr+='<p>融资周期: 短期</p>';
								tdStr+=' <p>联系电话: '+result[i].ContactUs+'</p>';
								tdStr+='</div>';
								tdStr+=' </div>';
								tdStr+='</div>';
								tdStr+='</div>';
								tdStr+='<div class="row">';
								tdStr+=' <div class="col-12 " style="margin: 0.3rem 0 0.3rem 0.5rem"><p>贷款倒计时：'+result[i].ProductReleaseTime+'</p></div>';
								tdStr+='</div>';
								tdStr+=' </div>';
								tdStr+='<div class="col_3 icon">';
								if(result[i].AuditStatus==0){
									tdStr+=' <img src="'+jpath+'/static/FrontStatic/image/icon_6.png" />';
								}else if(result[i].AuditStatus==1){
									tdStr+=' <img src="'+jpath+'/static/FrontStatic/image/icon_5.png" />';
								}
								tdStr+=' </div>';
								tdStr+='</div>';
								tdStr+='</div>';
								tdStr+='</div>';
							}else{
								tdStr+='<div class="row con_n" >';
								tdStr+='<div class="col-1"></div>';
								tdStr+='<div class="col-10 shadows" id="'+result[i].ProductId+'">';
								tdStr+='<div class="row">';
								tdStr+='<div class="col-12">';
								tdStr+='<div class="row">';
								tdStr+='<div class="col-6 special">';
								tdStr+='<h3>'+result[i].Money+'万元</h3>';
								tdStr+='<h5>'+result[i].Title+'</h5></div>';
								tdStr+='<div class="col-6 text">';
								tdStr+='<p>公司规模: '+result[i].Scale+'</p>';
								tdStr+='<p>融资周期: 短期</p>';
								tdStr+='<p>联系电话: '+result[i].ContactUs+'</p></div>';
								tdStr+='</div></div></div>';
								tdStr+='<div class="row">';
								tdStr+='<div class="col-12 " style="margin: 0.3rem 0 0.3rem 0.5rem"><p>贷款倒计时：'+result[i].ProductReleaseTime+'</p></div>';
								tdStr+='</div></div></div>';
							}
						}
					}
					_this.children().remove();
					_this.append(tdStr);
				}else{
					_this.children().remove();
				}
			});
		},getForm:function (){
			var _thisFrom=this;
			var dataJson="";
			var dataArr=[];
			_thisFrom.find(":input").each(function(e,_this){
				if($(_this).attr("type") == "radio"){
					if($(_this).is(":checked")){
						var iptName=$(_this).attr("name");
						if(iptName!="" && iptName!=null){
							dataArr.push(iptName+":'"+$(_this).val()+"'");
						}
					}
				}else{
					var iptName=$(_this).attr("name");
					if(iptName!="" && iptName!=null){
						dataArr.push(iptName+":'"+$(_this).val()+"'");
					}
				}
			});
			dataJson+="{"+dataArr.join(",")+"}";
			var jsonForms=eval("("+dataJson+")");
			return jsonForms;
		}
	});
	$.extend({
		loadComboxDom:function(formId,on_type){
			$("#"+formId).find("input[on_type='"+on_type+"']").each(function(e,_this){
				var selectId="select";
				var select_id=$(_this).attr("id");
				var select_value=$(_this).attr("value");
				var select_loadUrl=$(_this).attr("loadUrl");
				var select_no_name=$(_this).attr("no_name");
				var select_parMs=$(_this).attr("parMs");
				var selectStr="<select class='col-xs-10 col-sm-5' id='"+select_id+selectId+"'></select>";
				$(_this).after(selectStr);
				$.post(select_loadUrl,select_parMs,function(data){
					var json=$.parseJSON(data);
					var comboxJson=json.obj.results;
					var optionStr="<option value='-1'>请选择</option>";
					for(var i=0;i<comboxJson.length;i++){
						if(select_value=="" || select_value==null){
							optionStr+="<option value='"+comboxJson[i][''+select_id+''] +"'>"+comboxJson[i][''+select_no_name+'']+"</option>";
						}else{
							var selected="";
							if(select_value==comboxJson[i][''+select_id+'']){
								selected ="selected='selected'";
							}
							optionStr+="<option value='"+comboxJson[i][''+select_id+'']+"'  "+selected+">"+comboxJson[i][''+select_no_name+'']+"</option>";
						}
					}
					$("#"+select_id+selectId).append(optionStr);
				});
				$("#"+select_id+selectId).change(function(){
					var onVal=$(this).val();
					$(_this).attr("value",onVal);
					
				});
			});
		}
	});
});


